package meta

type VersionOption struct {
	Add bool
	Set int
}

type Version struct {
	*VersionOption
	*Base
}

func NewVersion(opt *VersionOption) *Version {
	return &Version{
		VersionOption: opt,
	}
}

func (s *Version) WithBase(base *Base) *Version {
	s.Base = base
	return s
}

func (s *Version) Run() error {
	metaCr, err := s.getMeta()
	if err != nil {
		return err
	}
	if s.Add {
		metaCr.Status.Version++
	}
	if s.Set != 0 {
		metaCr.Status.Version = s.Set
	}
	err = s.updateStatus(metaCr)
	if err != nil {
		return err
	}
	return nil
}
